package com.example.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public  class BaseService<T,E extends JpaRepository<T,Long>> implements IBaseService<T> {



    @Autowired
    public   E repository;


    @Override
    public List<T> getAll() {
        return repository.findAll();
    }

    @Override
    public T getById(int id) {
        return repository.findOne((long) id);
    }

    public T save(T t){
        return repository.save(t);
    }

    @Override
    public void delEntity(int id) {
        repository.delete((long) id);
    }


    public Page<T> getAll(Pageable pageable){
        return repository.findAll(pageable);
    }


    public T getById(String id){
        return  getById(Integer.valueOf(id));
    }

}
